package com.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.sfzy.entity.ChargingStandards;
import com.sfzy.service.ChargingStandardsService;
import com.sfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("chargingstandards")
public class ChargingStandardsController {
    @Autowired
    private ChargingStandardsService chargingStandardsService;
    //增加
    @PostMapping("add")
    public R insertChargingStandards(@RequestBody ChargingStandards chargingStandards) {
        int num = chargingStandardsService.insertChargingStandards(chargingStandards);
        return R.ok(num);
    }
    //删除
    @DeleteMapping("{id}")
    public R deleteChargingStandards(@PathVariable("id") int id) {
        int num = chargingStandardsService.deleteChargingStandards(id);
        return R.ok(num);
    }
    //修改
    @PutMapping("update")
    public R updateChargingStandards(@RequestBody ChargingStandards chargingStandards) {
        int num = chargingStandardsService.updateChargingStandards(chargingStandards);
        return R.ok(num);
    }
    //根据id查询
    @GetMapping("{id}")
    public R getChargingStandards(@PathVariable("id") int id) {
        ChargingStandards chargingStandards = chargingStandardsService.selectChargingStandardsById(id);
        return R.ok(chargingStandards);
    }
    //分页查询
    @GetMapping("page")
    public R getChargingStandardsPage(ChargingStandards chargingStandards,
                                      @RequestParam(required = false,defaultValue = "1")int pageNum,
                                      @RequestParam(required = false,defaultValue = "3")int pageSize) {
        PageInfo<ChargingStandards> chargingStandardsPageInfo = chargingStandardsService.selectChargingStandards(chargingStandards, pageNum, pageSize);
        return R .ok(chargingStandardsPageInfo);
    }
}
